﻿using System;
using System.Data;
using System.Collections.Generic;
using BangleCMS.Common;
using BangleCMS.Model;
namespace BangleCMS.BLL
{
	/// <summary>
	/// web_configBLL
	/// </summary>
	public partial class web_configBLL
	{
		private readonly BangleCMS.DAL.web_configDAL dal=new BangleCMS.DAL.web_configDAL();
		public web_configBLL()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ConfigId)
		{
			return dal.Exists(ConfigId);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BangleCMS.Model.web_config model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BangleCMS.Model.web_config model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ConfigId)
		{
			
			return dal.Delete(ConfigId);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string ConfigIdlist )
		{
			return dal.DeleteList(ConfigIdlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BangleCMS.Model.web_config GetModel(int ConfigId)
		{
			
			return dal.GetModel(ConfigId);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public BangleCMS.Model.web_config GetModelByCache(int ConfigId)
		{
			
			string CacheKey = "web_configModel-" + ConfigId;
			object objModel = BangleCMS.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(ConfigId);
					if (objModel != null)
					{
						int ModelCache = BangleCMS.Common.ConfigHelper.GetConfigInt("ModelCache");
						BangleCMS.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (BangleCMS.Model.web_config)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<BangleCMS.Model.web_config> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<BangleCMS.Model.web_config> DataTableToList(DataTable dt)
		{
			List<BangleCMS.Model.web_config> modelList = new List<BangleCMS.Model.web_config>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				BangleCMS.Model.web_config model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new BangleCMS.Model.web_config();
					if(dt.Rows[n]["ConfigId"]!=null && dt.Rows[n]["ConfigId"].ToString()!="")
					{
						model.ConfigId=int.Parse(dt.Rows[n]["ConfigId"].ToString());
					}
					if(dt.Rows[n]["ConfigKey"]!=null && dt.Rows[n]["ConfigKey"].ToString()!="")
					{
					model.ConfigKey=dt.Rows[n]["ConfigKey"].ToString();
					}
					if(dt.Rows[n]["ConfigValue"]!=null && dt.Rows[n]["ConfigValue"].ToString()!="")
					{
					model.ConfigValue=dt.Rows[n]["ConfigValue"].ToString();
					}
					if(dt.Rows[n]["Remark"]!=null && dt.Rows[n]["Remark"].ToString()!="")
					{
					model.Remark=dt.Rows[n]["Remark"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

